<template>
  <div>
    <myheader></myheader>
    <navtable></navtable>
    <b class="line"></b>
    <div class="clear"></div>
    <div class="center" style="margin-top:0px">
      <div class="col-main">
        <div class="main-wrap">

          <div class="user-comment">
            <!--标题 -->
            <div class="am-cf am-padding">
              <div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">消息管理</strong> / <small>Message&nbsp;</small></div>
            </div>
            <hr />
            <div>
              <el-table :data="messages" style="width: 100%">
                <el-table-column label="发送时间" width="150">
                  <template slot-scope="scope">
                    <p v-text="dateFormatter(scope.row.sendTime)"></p>
                  </template>
                </el-table-column>
                <el-table-column prop="sendName" label="发送人" width="120">
                </el-table-column>
                <el-table-column label="消息类型" width="120">
                  <template slot-scope="scope">
                    <em v-if="scope.row.msgType==0">系统消息</em>
                    <em v-if="scope.row.msgType==1">交易提醒</em>
                    <em v-if="scope.row.msgType==2">用户私信</em>
                  </template>
                </el-table-column>
                <el-table-column label="消息状态" width="120">
                  <template slot-scope="scope">
                    <em v-if="scope.row.msgStatus==0">未读</em>
                    <em v-if="scope.row.msgStatus==1">已读</em>
                  </template>
                </el-table-column>
                <el-table-column prop="msgContent" label="消息内容">
                  <template slot-scope="scope">
                    {{scope.row.msgContent}}
                  </template>
                </el-table-column>
                <el-table-column label="操作" width="150">
                  <template slot-scope="scope">
                    <el-button v-if="scope.row.msgStatus==0" @click="readMsg(scope.row.id)" type="text" size="small">已读</el-button>
                    <el-button type="text" size="small" @click="delMsg(scope.row.id)">删除</el-button>
                    <el-button v-if="scope.row.msgType==2" type="text" size="small">回复</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div class="block fr mt-30 mb-30">
              <el-pagination background @current-change="qryMessages" :current-page.sync="index" :page-size="pageSize" layout="prev, pager, next" :total="total">
              </el-pagination>
            </div>
          </div>

        </div>
        <!--底部-->
        <foot></foot>
      </div>
      <leftmenu></leftmenu>
    </div>
    <navfull></navfull>
  </div>
</template>

<script>
import myheader from '@/components/myheader.vue'
import navfull from '@/components/navfull.vue'
import navtable from '@/components/navtable.vue'
import leftmenu from '@/components/leftmenu.vue'
import foot from '@/components/foot.vue'
export default {
  name: 'messages',
  data () {
    return {
      index: 1,
      total: 10,
      pageSize: 10,
      messages: [],
      orders: [],
      flag: true
    }
  },
  components: {
    myheader,
    navfull,
    navtable,
    leftmenu,
    foot
  },
  mounted () {
    this.qryMessages();
  },
  methods: {
    qryMessages () {
      this.axios.get("/user/messages", {
        params: {
          index: this.index,
          pageSize: this.pageSize
        }
      }).then((res) => {
        var result = res.data;
        if (result.code == 200) {
          this.messages = result.data;
          this.total = result.total;
        }
      })
    },
    readMsg (id) {
      this.axios.get("/user/redMessage", {
        params: {
          messageId: id
        }
      }).then((res) => {
        let result = res.data;
        if (result.code == 200) {
          this.qryMessages();
        } else {
          this.$layer.msg("操作失败");
        }
      })
    },
    delMsg (id) {
      this.axios.delete("/user/message", {
        params: {
          messageId: id
        }
      }).then((res) => {
        let result = res.data;
        if (result.code == 200) {
          this.qryMessages();
          this.$layer.msg("删除成功");
        } else {
          this.$layer.msg("操作失败");
        }
      })
    },
    dateFormatter (date) {
      var time = new Date(date);
      var y = time.getFullYear();
      var m = time.getMonth() + 1;
      var d = time.getDate();
      var h = time.getHours();
      var mm = time.getMinutes();
      var s = time.getSeconds();
      return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);
    },
  }
}
function add0 (m) {
  return m < 10 ? '0' + m : m
}
</script>

<style scoped>
@import "../../../AmazeUI-2.4.2/assets/css/admin.css";
@import "../../../AmazeUI-2.4.2/assets/css/amazeui.css";
@import "../../../assets/css/personal.css";
@import "../../../assets/css/cmstyle.css";
@import "../../../assets/css/common/commonStyle.css";
</style>
